package com.jinpin.core.result;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.jinpin.core.enums.ResultEnum;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class ResultUtil {
    private Long code;
    private String msg;

    @JsonInclude(JsonInclude.Include.NON_EMPTY)
    private Object data;

    public ResultUtil(Long code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public static ResultUtil LoginSuccess(Long code, String msg, Object data) {
        return new ResultUtil(code, msg, data);
    }

    /**
     * 未授权返回结果
     */
    public static  ResultUtil forbidden(Object data) {
        return new ResultUtil(ResultEnum.FORBIDDEN.getCode(), ResultEnum.FORBIDDEN.getMsg(), data);
    }
    /**
     * 未登录返回结果
     */
    public static ResultUtil unauthorized(Object data) {
        return new ResultUtil(ResultEnum.UNAUTHORIZED.getCode(), ResultEnum.UNAUTHORIZED.getMsg(), data);
    }
}
